/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package three2learn.Controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.Transaction;
import three2learn.Model.Teacher;
import three2learn.service.HibernateUtil;

/**
 *
 * @author Lahhoud
 */
public class TeacherController extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction trans = session.beginTransaction();
        List<Teacher> teacherList;
        teacherList = session.createQuery("from Teacher").list();

        request.setAttribute("teachersFromSession", teacherList);
        request.setAttribute("amountOfTeachers", teacherList.size());

        String address = "/createTeacher.jsp";
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
        trans.commit();
    }
}
